<?php

class OrderBooksController extends Zend_Controller_Action{
    public function init(){

    }

    public function indexAction(){
        $filterOrderBooks = new Application_Form_FilterOrderBook();
        $filterOrderBooks->isValid($this->getRequest()->getParams());

        $orderBooksPaginator = Application_Model_OrderBooks::getInstance()
            ->getPaginatorForFilter($filterOrderBooks->getValues());
        $orderBooksPaginator->setItemCountPerPage(12);
        $page = $this->getRequest()->getParam('page');
        if(!is_null($page)){
            $orderBooksPaginator->setCurrentPageNumber($page);
        }
        $this->view->filterOrderBooks = $filterOrderBooks;
        $this->view->filterParams = $this->getRequest()->getParams();
        $this->view->orderBooksPaginator = $orderBooksPaginator;
    }

    public function addAction(){
        $formOrderBook = new Application_Form_OrderBook();
        $request = $this->getRequest();
        if($request->isPost()){
            if($formOrderBook->isValid($request->getPost())){
                Application_Model_OrderBooks::getInstance()->add($formOrderBook->getValues());
                $this->redirect($this->view->url(array('controller' => 'order-books'), null, true));
            }
        }
        $this->view->formOrderBook = $formOrderBook;
    }
}